home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 August - Disc 1 / PCNET_CD_2006_08_1.iso / shareware / AutoHotkey104407_Install.exe / Extras / Run this to install syntax highlighting for UltraEdit.ahk < prev    next >
Encoding:
Text File  |  2005-11-15  |  9.9 KB  |  249 lines

  1. ;##############################################################################
  2. ;#
  3. ;#  Add or update syntax highlighting for AutoHotKey scripts in UltraEdit
  4. ;#
  5. ;#  Mod of a script done by Tekl (although not much has survived)
  6. ;#  Mod done by toralf, 2005-11-14
  7. ;#
  8. ;#  Tested with: AHK 1.0.40.06, UltraEdit 11.10a
  9. ;#
  10. ;#  Requirements
  11. ;#    - Syntax files for AHK in one directory
  12. ;#    - UltraEdit uses standard file for highlighting => wordfile.txt
  13. ;#
  14. ;#  Customize:
  15. ;#    - The default color for strings is gray, change it to any color
  16. ;#         you want to have "string" to appeer => Extra->Option->syntaxhiglighting
  17. ;#    - Change the default color for up to 8 keyword groups
  18. ;#         => Extra->Option->syntaxhiglighting
  19. ;#    -specify up to 8 syntax files, each containing one keyword per line
  20. ;#         => you can add your own files, for keywords that you want to highlight
  21. ;#            Personally I use 3 additional: Operators, Separators and Special
  22. ;#            The content of these files is posted further down
  23. ;#
  24.  
  25. ; Specify a list of up to 8 syntax files; the order influences the color given to them by UE by default
  26. SyntaxFileNameList = CommandNames|Keywords|Variables|Functions|Keys|Operators|Separators|Special
  27. ;Default colors in UE:  blue     |red     |orange   |green    |brown|blue    |blue      |blue
  28.  
  29. SyntaxExtention = .txt
  30.  
  31. ;#############   END of Customization Area   ##################################
  32.  
  33. ;#############   Ask and Check for valid input  ###############################
  34.  
  35. RegRead, UeditPath, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\UEDIT32.exe,Path
  36. IfNotExist, %UeditPath%\uedit32.exe
  37.   {
  38.     UeditPath = %A_ProgramFiles%\UltraEdit
  39.     IfNotExist, %UeditPath%\uedit32.exe
  40.       {
  41.         FileSelectFolder, UeditPath,*%A_ProgramFiles%, 0, Select UltraEdit program-folder
  42.         IfNotExist, %UeditPath%\uedit32.exe
  43.           {
  44.             MsgBox UltraEdit cannot be found.
  45.             ExitApp
  46.           }
  47.       }
  48.   }
  49.  
  50. UEini = %APPDATA%\IDMComp\UltraEdit\uedit32.ini
  51. IfNotExist, %UEini%
  52.   {
  53.     UEini = %A_WinDir%\uedit32.ini
  54.     IfNotExist, %UEini%
  55.         FileSelectFile, UEini, 1, %A_ProgramFiles%\UltraEdit, Select UltraEdit INI-File, *.ini
  56.   }
  57. IniRead, UEwordfile, %UEini%, Settings, Language File
  58. If UEwordfile = Error
  59.   {
  60.     MsgBox INI-File "%UEini%" is missing the Key "Language File".
  61.     ExitApp
  62.   }
  63.  
  64. ;Search or ask for Wordfile, when it doesn't exist -> exit
  65. UEwordfile = %UeditPath%\wordfile.txt
  66. IfNotExist, %UEwordfile%
  67.   {
  68.     FileSelectFile, UEwordfile, 1, %A_ProgramFiles%, Select UltraEdit wordfile, *.txt
  69.     IfNotExist, %UEwordfile%
  70.       {
  71.         MsgBox, 16,, UltraEdit Wordfile cannot be found.
  72.         ExitApp
  73.       }
  74.   }
  75.  
  76. ; Search or ask for specified syntax folder and files, when they don't exist -> exit
  77. ; Get path of AHK Installation so that syntax files can be found more reliably:
  78. RegRead, ahkpath, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
  79. PathSyntaxFiles = %ahkpath%\AutoHotkey\Extras\Editors\Syntax
  80. IfNotExist, %PathSyntaxFiles%
  81.   {
  82.     PathSyntaxFiles = %A_ProgramFiles%\AutoHotkey\Extras\Editors\Syntax
  83.     IfNotExist, %PathSyntaxFiles%
  84.       {
  85.         FileSelectFolder, PathSyntaxFiles, *%A_ProgramFiles%,0, Select Folder "AutoHotkey\Extras\Editors\Syntax"
  86.         IfNotExist, %PathSyntaxFiles%
  87.           {
  88.             MsgBox, 16,, Folder containing syntax files not found.
  89.             ExitApp
  90.           }
  91.       }
  92.   }
  93.  
  94. MissingFile =
  95. FileCount = 0
  96. Loop, Parse, SyntaxFileNameList, |
  97.   {
  98.     FileCount += 1
  99.     IfNotExist, %PathSyntaxFiles%\%A_LoopField%%SyntaxExtention%
  100.         MissingFile = %MissingFile%`n%A_LoopField%%SyntaxExtention%
  101.   }
  102. If MissingFile is not Space
  103.   {
  104.     MsgBox, 16,, AHK Syntax file(s)`n%MissingFile%`n`ncannot be found in`n`n%PathSyntaxFiles%\.
  105.     ExitApp
  106.   }
  107. If FileCount > 8
  108.   {
  109.     MsgBox, 16,, You have specified %FileCount% Syntax files.`nOnly 8 are supported be UltraEdit.`nPlease shorten the list.
  110.     ExitApp
  111.   }
  112.  
  113. ;Check the number of languages in the current wordfile, if more than 19 without AHK -> exit
  114. NumberOfLanguages = 0
  115. Loop, Read, %UEwordfile%
  116.   {
  117.     StringLeft, WFdef, A_LoopReadLine, 2
  118.     If WFdef = /L
  119.       {
  120.         StringSplit, WFname, A_LoopReadLine, "      ;"
  121.         LanguageName = %WFname2%
  122.         If LanguageName <> AutoHotkey
  123.             NumberOfLanguages += 1
  124.       }
  125.   }
  126. If NumberOfLanguages > 19
  127.   {
  128.     MsgBox, 48,, The wordfile has %NumberOfLanguages% syntax-schemes. UltraEdit does only support 20 schemes.`nPlease Delete schemes from the file!
  129.     ExitApp
  130.   }
  131.  
  132. ;#############   Read keywords from syntax files into arrays   ################
  133.  
  134. Loop, Parse, SyntaxFileNameList, |  ;Read all syntax files
  135.   {
  136.     SyntaxFileName = %A_LoopField%
  137.     Gosub, ReadSyntaxFromFile       ;SyntaxFileName will become string with keywords
  138.   }
  139.  
  140. ;#############   Build language specific highlight for AHK   ##################
  141.  
  142. StrgAHKwf = "AutoHotkey" Nocase
  143. StrgAHKwf = %StrgAHKwf% Line Comment = `;
  144. StrgAHKwf = %StrgAHKwf% Line Comment Preceding Chars = [~``]     ;to Escape Escaped ;
  145. StrgAHKwf = %StrgAHKwf% Escape Char = ``
  146. StrgAHKwf = %StrgAHKwf% String Chars = "                                                   ;"
  147. StrgAHKwf = %StrgAHKwf% Block Comment On = /*
  148. StrgAHKwf = %StrgAHKwf% Block Comment Off = */
  149. StrgAHKwf = %StrgAHKwf% File Extensions = ahk`n
  150. StrgAHKwf = %StrgAHKwf%/DeLimiters = *~`%+-!^&(){}=|\/:"'``;<>%A_Tab%,%A_Space%.`n         ;"
  151. StrgAHKwf = %StrgAHKwf%/Indent Strings = "{" ":" "("`n
  152. StrgAHKwf = %StrgAHKwf%/Unindent Strings = "}" "Return" "Else" ")"`n
  153. StrgAHKwf = %StrgAHKwf%/Open Fold Strings = "{"`n
  154. StrgAHKwf = %StrgAHKwf%/Close Fold Strings = "}"`n
  155. StrgAHKwf = %StrgAHKwf%/Function String = "`%[^t ]++^(:[^*^?BbCcKkOoPpRrZz0-9- ]++:*`::^)"`n   ; Hotstrings
  156. StrgAHKwf = %StrgAHKwf%/Function String 1 = "`%[^t ]++^([a-zA-Z0-9 #!^^&<>^*^~^$]+`::^)"`n     ; Hotkeys
  157. StrgAHKwf = %StrgAHKwf%/Function String 2 = "`%[^t ]++^([a-zA-Z0-9Σ÷ⁿ▀#_@^$^?^[^]]+:^)"`n      ; Subroutines
  158. StrgAHKwf = %StrgAHKwf%/Function String 3 = "`%[^t ]++^([a-zA-Z0-9Σ÷ⁿ▀#_@^$^?^[^]]+(*)^)"`n    ; Functions
  159. StrgAHKwf = %StrgAHKwf%/Function String 4 = "`%[^t ]++^(#[a-zA-Z]+ ^)"`n                       ; Directives
  160.  
  161. Loop, Parse, SyntaxFileNameList, |      ;Add the keywords from syntax strings into their Sections
  162.   {
  163.     StrgAHKwf = %StrgAHKwf%/C%A_Index%"%A_LoopField%"   ;Section definition
  164.     SyntaxString = %A_LoopField%             ;which Section/syntax
  165.     Gosub, ParseSyntaxString                 ;Parse through string and add to list
  166.   }
  167.  
  168. ;#############   Add or Update Wordfile   #####################################
  169.  
  170. ;Name of a file for temporary store the word file
  171. TemporaryUEwordFile = TempUEwordFile.txt
  172. FileDelete, %TemporaryUEwordFile%
  173.  
  174. Loop, Read, %UEwordfile%, %TemporaryUEwordFile%   ;Read through Wordfile
  175.   {
  176.     StringLeft, WFdef, A_LoopReadLine, 2
  177.     If WFdef = /L
  178.       {
  179.         StringSplit, WFname, A_LoopReadLine, "                  ;"
  180.         LanguageName = %WFname2%
  181.         LanguageNumber = %WFname1%
  182.         StringTrimLeft,LanguageNumber,LanguageNumber,2
  183.         If LanguageName = AutoHotkey         ;when AHK Section found, place new Section at same location
  184.           {
  185.             FileAppend, /L%LanguageNumber%%StrgAHKwf%
  186.             AHKLanguageFound := True
  187.           }
  188.       }
  189.     If LanguageName <> AutoHotkey            ;everything that does not belong to AHK, gets unchanged to file
  190.         FileAppend, %A_LoopReadLine%`n
  191.   }
  192.  
  193. If not AHKLanguageFound                      ;when AHK Section not found, append AHK Section
  194.   {
  195.     LanguageNumber += 1
  196.     FileAppend, /L%LanguageNumber%%StrgAHKwf%, %TemporaryUEwordFile%
  197.   }
  198.  
  199. FileCopy, %UEwordfile%, %UEwordfile%.ahk.bak, 1    ;Create Backup of current wordfile
  200. FileMove, %TemporaryUEwordFile%, %UEwordfile%, 1       ;Replace wordfile with temporary file
  201.  
  202. ; Tell user what has been done
  203. Question = `n`nWould you like to make UltraEdit the Default editor for AutoHotkey scripts (.ahk files)?
  204. If AHKLanguageFound
  205.     MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been updated in your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%
  206. Else
  207.     MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been added to your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%
  208.  
  209. IfMsgBox, Yes
  210.     RegWrite, REG_SZ, HKEY_CLASSES_ROOT, AutoHotkeyScript\Shell\Edit\Command,, %UeditPath%\uedit32.exe "`%1"
  211.  
  212. ExitApp  ; That's it, exit
  213.  
  214. ;#############   SubRoutines   ################################################
  215.  
  216. ReadSyntaxFromFile:
  217.   TempString =
  218.   Loop, Read , %PathSyntaxFiles%\%SyntaxFileName%%SyntaxExtention%   ;read syntax file
  219.     {
  220.       StringLeft,Char, A_LoopReadLine ,1
  221.       ;if line is comment, don't bother, otherwise add keyword to string
  222.       If Char <> `;
  223.         {
  224.           ;only add first word in line
  225.           Loop Parse, A_LoopReadLine, `,%A_Tab%%A_Space%(
  226.             {
  227.               TempString = %TempString%%A_LoopField%`n
  228.               Break
  229.             }
  230.         }
  231.     }
  232.   %SyntaxFileName% = %TempString%                          ;Assign string to syntax filename
  233.   Sort, %SyntaxFileName%, U                                ;Sort keywords in string
  234. Return
  235.  
  236. ParseSyntaxString:
  237.   Loop, Parse, %SyntaxString%, `n                 ;Parse through syntax string
  238.     {
  239.       StringLeft, Char, A_LoopField,1
  240.       If (Char = PrevChar)                       ;add keyword to line when first character is same with previous keyword
  241.           StrgAHKwf = %StrgAHKwf% %A_LoopField%
  242.       Else                                       ;for every keyword with a new first letter, start a new row
  243.           StrgAHKwf = %StrgAHKwf%`n%A_LoopField%
  244.       PrevChar = %Char%                          ;remember first character of keyword
  245.     }
  246. Return
  247.  
  248. ;#############   END of File   ################################################
  249.